﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UCS.Logic;
using UCS.Helpers;

namespace UCS.PacketProcessing
{
    //Packet 24301
    class AllianceDataMessage : Message
    {
        private Alliance m_vAlliance;

        public AllianceDataMessage(Client client, Alliance alliance)
            : base(client)
        {
            SetMessageType(24301);
            m_vAlliance = alliance;
        }

        //00 00 00 3B 00 0A 40 1E 
        //00 00 00 0B 
        //4F 6E 20 74 68 65 20 6D 6F 75 6E 
        //63 00 01 58 
        //00 00 00 01 
        //00 00 00 2D 
        //00 00 21 72 
        //00 00 00 00 
        //00 00 00 0F 
        //00 00 00 1C 
        //00 00 00 00 
        //00 1E 84 81 
        //00 00 00 01 
        //01 E8 48 57 
        //00 00 02 91 
        //00 00 00 04 
        //00 00 00 29 41 75 63 75 6E 65 20 70 72 69 73 65 20 64 65 20 74 C3 AA 74 65 2E 50 6F 6C 69 74 65 73 73 65 20 64 65 6D 61 6E 64 65 72 2E 
        //00 00 00 04 
        //01 
        //00 00 00 38 
        //00 18 52 18 //fin desc clan et début joueurs
        //00 00 00 2D 
        //00 00 00 2A 00 17 E8 BD 00 00 00 06 6B 61 69 73 65 72 00 00 00 02 00 00 00 58 00 00 00 00 00 00 0B 0C 00 00 00 83 00 00 00 5B 00 00 00 01 00 00 00 01 00 00 01 15 7A 00 00 00 01 01 00 00 00 2A 00 17 E8 BD 00 00 00 2E 00 41 06 60 00 00 00 06 63 68 74 69 34 30 00 00 00 01 00 00 00 3E 00 00 00 00 00 00 05 74 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 02 00 00 00 00 00 00 00 00 01 01 00 00 00 2E 00 41 06 60 00 00 00 2B 00 08 BC 20 00 00 00 08 48 61 77 61 69 20 34 30 00 00 00 01 00 00 00 39 00 00 00 00 00 00 05 4D 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 03 00 00 00 00 00 00 00 00 01 01 00 00 00 2B 00 08 BC 20 00 00 00 10 00 58 56 28 00 00 00 04 74 6F 74 6F 00 00 00 03 00 00 00 43 00 00 00 00 00 00 04 D4 00 00 00 0E 00 00 00 14 00 00 00 04 00 00 00 04 00 00 00 00 00 00 00 00 01 01 00 00 00 10 00 58 56 28 00 00 00 15 00 59 0D B5 00 00 00 04 79 61 6E 6E 00 00 00 04 00 00 00 46 00 00 00 00 00 00 04 6F 00 00 00 14 00 00 00 19 00 00 00 05 00 00 00 05 00 00 01 15 7A 00 00 00 01 01 00 00 00 15 00 59 0D B5 00 00 00 05 00 72 C3 56 00 00 00 0A 4B 65 76 45 78 74 72 65 6D 65 00 00 00 04 00 00 00 2D 00 00 00 00 00 00 04 3B 00 00 00 2A 00 00 00 15 00 00 00 06 00 00 00 06 00 00 01 15 7A 00 00 00 01 01 00 00 00 05 00 72 C3 56 00 00 00 2F 00 8B B1 9E 00 00 00 06 41 72 6E 61 75 64 00 00 00 03 00 00 00 1E 00 00 00 00 00 00 04 05 00 00 00 3F 00 00 00 39 00 00 00 07 00 00 00 07 00 00 01 15 7A 00 00 00 01 01 00 00 00 2F 00 8B B1 9E 00 00 00 47 00 6D D7 E8 00 00 00 07 63 68 61 72 6F 6C 65 00 00 00 01 00 00 00 1C 00 00 00 00 00 00 03 EC 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 08 00 00 01 15 7A 00 00 00 01 01 00 00 00 47 00 6D D7 E8 00 00 00 1D 00 7A 1A 70 00 00 00 05 4A 61 79 4C 50 00 00 00 01 00 00 00 24 00 00 00 00 00 00 03 7B 00 00 00 00 00 00 00 00 00 00 00 09 00 00 00 09 00 00 01 15 7A 00 00 00 01 01 00 00 00 1D 00 7A 1A 70 00 00 00 0E 00 11 C9 BC 00 00 00 06 78 61 76 69 65 72 00 00 00 03 00 00 00 55 00 00 00 03 00 00 03 11 00 00 00 5B 00 00 00 39 00 00 00 0A 00 00 00 0A 00 00 01 15 7A 00 00 00 01 01 00 00 00 0E 00 11 C9 BC 00 00 00 2D 00 78 C0 76 00 00 00 04 72 65 6D 79 00 00 00 01 00 00 00 14 00 00 00 03 00 00 02 E0 00 00 00 0A 00 00 00 00 00 00 00 0B 00 00 00 0B 00 00 01 15 7A 00 00 00 01 01 00 00 00 2D 00 78 C0 76 00 00 00 18 00 83 CD 54 00 00 00 04 73 61 69 64 00 00 00 01 00 00 00 0D 00 00 00 00 00 00 02 C7 00 00 00 00 00 00 00 00 00 00 00 0C 00 00 00 0C 00 00 00 00 00 00 00 00 00 01 00 00 00 18 00 83 CD 54 00 00 00 3D 00 76 AA DE 00 00 00 08 62 72 69 61 63 31 33 30 00 00 00 01 00 00 00 14 00 00 00 00 00 00 02 B0 00 00 00 00 00 00 00 00 00 00 00 0D 00 00 00 0D 00 00 01 15 7A 00 00 00 01 01 00 00 00 3D 00 76 AA DE 00 00 00 41 00 47 4F 7C 00 00 00 04 6A 6F 68 6E 00 00 00 01 00 00 00 0E 00 00 00 00 00 00 02 72 00 00 00 00 00 00 00 00 00 00 00 0E 00 00 00 0E 00 00 00 00 00 00 00 00 00 01 00 00 00 41 00 47 4F 7C 00 00 00 3F 00 5E 4A 96 00 00 00 08 74 69 6D C3 A9 6F 36 37 00 00 00 01 00 00 00 0D 00 00 00 00 00 00 02 65 00 00 00 00 00 00 00 00 00 00 00 0F 00 00 00 0F 00 00 01 15 7A 00 00 00 01 01 00 00 00 3F 00 5E 4A 96 00 00 00 38 00 94 A5 B2 00 00 00 08 5A 61 70 69 78 6E 65 74 00 00 00 01 00 00 00 0C 00 00 00 02 00 00 02 47 00 00 00 15 00 00 00 0A 00 00 00 10 00 00 00 00 01 00 00 00 00 00 00 00 00 01 00 00 00 38 00 94 A5 B2 00 00 00 14 00 7C 79 26 00 00 00 05 6D 61 74 74 79 00 00 00 01 00 00 00 11 00 00 00 00 00 00 02 30 00 00 00 00 00 00 00 00 00 00 00 11 00 00 00 10 00 00 01 15 7A 00 00 00 01 01 00 00 00 14 00 7C 79 26 00 00 00 2D 00 9A 6B B0 00 00 00 03 6A 68 67 00 00 00 01 00 00 00 11 00 00 00 00 00 00 02 1A 00 00 00 00 00 00 00 00 00 00 00 12 00 00 00 12 00 00 01 15 7A 00 00 00 01 01 00 00 00 2D 00 9A 6B B0 00 00 00 30 00 98 CB EB 00 00 00 04 73 61 69 66 00 00 00 01 00 00 00 11 00 00 00 02 00 00 02 18 00 00 00 00 00 00 00 35 00 00 00 13 00 00 00 15 01 00 01 15 7A 00 00 00 01 01 00 00 00 30 00 98 CB EB 00 00 00 20 00 22 9E 64 00 00 00 07 66 6F 77 6A 66 68 66 00 00 00 03 00 00 00 0E 00 00 00 00 00 00 02 10 00 00 00 00 00 00 00 00 00 00 00 14 00 00 00 11 00 00 00 00 00 00 00 00 00 01 00 00 00 20 00 22 9E 64 00 00 00 07 00 8B 36 D3 00 00 00 07 6C 6F 72 64 6F 63 6B 00 00 00 01 00 00 00 08 00 00 00 00 00 00 01 E7 00 00 00 00 00 00 00 00 00 00 00 15 00 00 00 13 00 00 01 15 7A 00 00 00 01 01 00 00 00 07 00 8B 36 D3 00 00 00 22 00 0F 6A 4A 00 00 00 09 62 65 6E 62 6F 75 74 37 39 00 00 00 01 00 00 00 0C 00 00 00 00 00 00 01 BC 00 00 00 00 00 00 00 00 00 00 00 16 00 00 00 14 00 00 01 15 7A 00 00 00 01 01 00 00 00 22 00 0F 6A 4A 00 00 00 47 00 7E 43 4D 00 00 00 08 4D 6F 72 67 61 6E 65 2E 00 00 00 01 00 00 00 0A 00 00 00 01 00 00 01 BC 00 00 00 0A 00 00 00 4E 00 00 00 17 00 00 00 1F 00 00 01 15 7A 00 00 00 01 01 00 00 00 47 00 7E 43 4D 00 00 00 2D 00 52 52 26 00 00 00 0E 66 61 73 74 65 72 2D 65 61 67 6C 65 32 34 00 00 00 01 00 00 00 0B 00 00 00 00 00 00 01 72 00 00 00 00 00 00 00 00 00 00 00 18 00 00 00 16 01 00 01 15 7A 00 00 00 01 01 00 00 00 2D 00 52 52 26 00 00 00 22 00 58 F4 BE 00 00 00 19 49 20 4C 4F 56 45 20 59 4F 55 E2 99 A1 E2 99 A1 E2 99 A1 E2 99 A1 E2 99 A1 00 00 00 01 00 00 00 0A 00 00 00 00 00 00 01 6E 00 00 00 00 00 00 00 00 00 00 00 19 00 00 00 19 00 00 00 00 00 00 00 00 00 01 00 00 00 22 00 58 F4 BE 00 00 00 2A 00 98 C4 70 00 00 00 0A 6D 72 67 6F 6F 64 66 6C 6F 77 00 00 00 01 00 00 00 11 00 00 00 00 00 00 01 66 00 00 00 00 00 00 00 14 00 00 00 1A 00 00 00 18 00 00 01 15 7A 00 00 00 01 01 00 00 00 2A 00 98 C4 70 00 00 00 2D 00 9D F0 F6 00 00 00 0B 6A 75 73 74 69 6E 65 62 63 6B 72 00 00 00 01 00 00 00 0E 00 00 00 00 00 00 01 66 00 00 00 1F 00 00 00 00 00 00 00 1B 00 00 00 22 01 00 01 15 7A 00 00 00 01 01 00 00 00 2D 00 9D F0 F6 00 00 00 13 00 99 4D 5A 00 00 00 06 6D 61 64 61 6E 69 00 00 00 01 00 00 00 0B 00 00 00 00 00 00 01 60 00 00 00 0D 00 00 00 14 00 00 00 1C 00 00 00 00 01 00 01 B4 C3 00 00 00 01 01 00 00 00 13 00 99 4D 5A 00 00 00 2F 00 81 F8 2F 00 00 00 10 44 69 61 64 69 C3 A9 53 74 75 72 72 69 64 67 65 00 00 00 01 00 00 00 07 00 00 00 00 00 00 01 59 00 00 00 00 00 00 00 00 00 00 00 1D 00 00 00 1A 00 00 01 15 7A 00 00 00 01 01 00 00 00 2F 00 81 F8 2F 00 00 00 16 00 93 EE 1D 00 00 00 0A 61 73 20 62 72 61 76 6F 6E 65 00 00 00 01 00 00 00 0B 00 00 00 00 00 00 01 52 00 00 00 00 00 00 00 14 00 00 00 1E 00 00 00 1C 00 00 01 15 7A 00 00 00 01 01 00 00 00 16 00 93 EE 1D 00 00 00 40 00 86 1A 2F 00 00 00 05 53 61 72 61 68 00 00 00 01 00 00 00 12 00 00 00 00 00 00 01 48 00 00 00 00 00 00 00 00 00 00 00 1F 00 00 00 1B 00 00 01 15 7A 00 00 00 01 01 00 00 00 40 00 86 1A 2F 00 00 00 2F 00 93 FE C7 00 00 00 04 6E 79 6E 79 00 00 00 01 00 00 00 0E 00 00 00 00 00 00 01 1B 00 00 00 00 00 00 00 00 00 00 00 20 00 00 00 23 00 00 01 15 7A 00 00 00 01 01 00 00 00 2F 00 93 FE C7 00 00 00 11 00 9B 56 CD 00 00 00 07 67 61 6E 67 6C 6F 79 00 00 00 01 00 00 00 07 00 00 00 00 00 00 00 F9 00 00 00 00 00 00 00 00 00 00 00 21 00 00 00 1E 00 00 00 00 00 00 00 00 00 01 00 00 00 11 00 9B 56 CD 00 00 00 13 00 8B 50 59 00 00 00 05 6B 65 76 69 6E 00 00 00 01 00 00 00 07 00 00 00 00 00 00 00 ED 00 00 00 00 00 00 00 00 00 00 00 22 00 00 00 20 00 00 01 15 7A 00 00 00 01 01 00 00 00 13 00 8B 50 59 00 00 00 44 00 7B 2D 50 00 00 00 07 73 6C 61 6E 64 65 72 00 00 00 01 00 00 00 10 00 00 00 00 00 00 00 C7 00 00 00 00 00 00 00 00 00 00 00 23 00 00 00 21 01 00 01 15 7A 00 00 00 01 01 00 00 00 44 00 7B 2D 50 00 00 00 26 00 9C EA B1 00 00 00 04 6C 75 6B 61 00 00 00 01 00 00 00 07 00 00 00 00 00 00 00 C3 00 00 00 00 00 00 00 00 00 00 00 24 00 00 00 25 00 00 01 15 7A 00 00 00 01 01 00 00 00 26 00 9C EA B1 00 00 00 25 00 97 D0 4A 00 00 00 06 77 61 73 73 69 6D 00 00 00 01 00 00 00 09 00 00 00 00 00 00 00 B4 00 00 00 0D 00 00 00 0A 00 00 00 25 00 00 00 27 01 00 01 15 7A 00 00 00 01 01 00 00 00 25 00 97 D0 4A 00 00 00 46 00 7C 4D FA 00 00 00 0A 6C 65 20 6D 6F 6E 73 74 72 65 00 00 00 01 00 00 00 09 00 00 00 00 00 00 00 A4 00 00 00 00 00 00 00 00 00 00 00 26 00 00 00 24 00 00 01 15 7A 00 00 00 01 01 00 00 00 46 00 7C 4D FA 00 00 00 15 00 99 76 6C 00 00 00 06 65 6C 69 6F 74 74 00 00 00 01 00 00 00 08 00 00 00 00 00 00 00 9B 00 00 00 00 00 00 00 00 00 00 00 27 00 00 00 26 00 00 00 00 00 00 00 00 00 01 00 00 00 15 00 99 76 6C 00 00 00 33 00 9A D1 FE 00 00 00 0B 66 61 65 63 65 6C 20 74 68 75 67 00 00 00 01 00 00 00 08 00 00 00 00 00 00 00 8A 00 00 00 00 00 00 00 00 00 00 00 28 00 00 00 28 01 00 00 00 00 00 00 00 01 01 00 00 00 33 00 9A D1 FE 00 00 00 15 00 58 4D 94 00 00 00 0C 69 69 69 69 69 69 69 69 69 69 69 69 00 00 00 01 00 00 00 07 00 00 00 00 00 00 00 26 00 00 00 00 00 00 00 00 00 00 00 29 00 00 00 00 01 00 00 00 00 00 00 00 01 01 00 00 00 15 00 58 4D 94 00 00 00 0C 00 9A 39 48 00 00 00 07 41 72 74 65 6D 69 73 00 00 00 01 00 00 00 0C 00 00 00 00 00 00 00 14 00 00 00 38 00 00 00 0A 00 00 00 2A 00 00 00 29 01 00 00 00 00 00 00 00 01 01 00 00 00 0C 00 9A 39 47 00 00 00 1D 00 85 F5 3C 00 00 00 06 6D 61 74 68 65 6F 00 00 00 01 00 00 00 06 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00 00 00 00 00 2B 00 00 00 2A 00 00 00 00 00 00 00 00 00 01 00 00 00 1D 00 85 F5 3C 00 00 00 23 00 4D 93 EC 00 00 00 08 6E 75 6D 62 65 72 20 31 00 00 00 01 00 00 00 09 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00 00 00 00 00 2C 00 00 00 2B 00 00 00 00 00 00 00 00 01 01 00 00 00 23 00 4D 93 EC 00 00 00 47 00 45 A3 F8 00 00 00 04 6A 75 6A 75 00 00 00 01 00 00 00 09 00 00 00 00 00 00 00 14 00 00 00 00 00 00 00 00 00 00 00 2D 00 00 00 2C 00 00 00 00 00 00 00 00 01 01 00 00 00 47 00 45 A3 F8
        
        public override void Encode()
        {
            List<Byte> pack = new List<Byte>();

            var allianceMembers = m_vAlliance.GetAllianceMembers();//avoid concurrent access issues

            pack.AddRange(m_vAlliance.EncodeFullEntry());
            pack.AddString(m_vAlliance.GetAllianceDescription());
            pack.AddInt32(0x04);
            pack.Add(1);
            pack.AddInt32(0x03);
            pack.AddInt32(0x0008A5DF);

            pack.AddInt32(allianceMembers.Count);
            foreach(var allianceMember in allianceMembers)
            {
                pack.AddRange(allianceMember.Encode());
            }

            SetData(pack.ToArray());
        }
    }
}
